package course.cmsc436.medicationmanager;

import course.cmsc436.medicationmanager.UPCFetcher.FetchCompleteListener;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class UPCTestActivity extends Activity implements NDCFetcher.FetchCompleteListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_upctest);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.upctest, menu);
		return true;
	}
	
	public void submitUPC(View v) {
		EditText upctext = (EditText)this.findViewById(R.id.editText1);
		String entry = upctext.getText().toString();
		Button b = (Button)this.findViewById(R.id.upcsubmit);
		b.setEnabled(false);
		NDCFetcher.doAsync(entry, this);
	}

	@Override
	public void onFetchComplete(String desc) {
		TextView descView = (TextView)this.findViewById(R.id.upctestdesc);
		descView.setText(desc);
		Button b = (Button)this.findViewById(R.id.upcsubmit);
		b.setEnabled(true);
	}
}
